[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1 Sending Mail

To send a message in Emacs, you start by typing a command (C-x m) to select and initialize the ‘*mail*’ buffer. Then you edit the text and headers of the message in this buffer, and type another command (C-c C-c) to send the message.

C-x m

Begin composing a message to send (mail).

C-x 4 m

Likewise, but display the message in another window (mail-other-window).

C-x 5 m

Likewise, but make a new frame (mail-other-frame).

C-c C-c

In Mail mode, send the message and switch to another buffer (mail-send-and-exit).

The command C-x m (mail) selects a buffer named ‘*mail*’ and initializes it with the skeleton of an outgoing message. C-x 4 m (mail-other-window) selects the ‘*mail*’ buffer in a different window, leaving the previous current buffer visible. C-x 5 m (mail-other-frame) creates a new frame to select the ‘*mail*’ buffer.

Because the mail composition buffer is an ordinary Emacs buffer, you can switch to other buffers while in the middle of composing mail, and switch back later (or never). If you use the C-x m command again when you have been composing another message but have not sent it, you are asked to confirm before the old message is erased. If you answer n, the ‘*mail*’ buffer is left selected with its old contents, so you can finish the old message and send it. C-u C-x m is another way to do this. Sending the message marks the ‘*mail*’ buffer “unmodified”, which avoids the need for confirmation when C-x m is next used.

If you are composing a message in the ‘*mail*’ buffer and want to send another message before finishing the first, rename the ‘*mail*’ buffer using M-x rename-uniquely (@pxref{Misc Buffer}). Then you can use C-x m or its variants described above to make a new ‘*mail’ buffer. Once you’ve done that, you can work with each mail buffer independently.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.1 The Format of the Mail Buffer

In addition to the text or body, a message has header fields which say who sent it, when, to whom, why, and so on. Some header fields such as the date and sender are created automatically after the message is sent. Others, such as the recipient names, must be specified by you in order to send the message properly.

Mail mode provides a few commands to help you edit some header fields, and some are preinitialized in the buffer automatically at times. You can insert or edit any header fields using ordinary editing commands.

The line in the buffer that says

--text follows this line--

is a special delimiter that separates the headers you have specified from the text. Whatever follows this line is the text of the message; the headers precede it. The delimiter line itself does not appear in the message actually sent. The text used for the delimiter line is controlled by the variable mail-header-separator.

Here is an example of what the headers and text in the ‘*mail*’ buffer might look like.

To: gnu@prep.ai.mit.edu
CC: lungfish@spam.org, byob@spam.org
Subject: The Emacs Manual
--Text follows this line--
Please ignore this message.

[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.2 Mail Header Fields

There are several header fields you can use in the ‘*mail*’ buffer. Each header field starts with a field name at the beginning of a line, terminated by a colon. Upper and lower case are equivalent in field names (and in mailing addresses also). After the colon and optional whitespace comes the contents of the field.

To

This field contains the mailing addresses to which the message is addressed.

Subject

The contents of the ‘Subject’ field should be a piece of text that says what the message is about. The reason ‘Subject’ fields are useful is that most mail-reading programs can provide a summary of messages, listing the subject of each message but not its text.

CC

This field contains additional mailing addresses to send the message to, but whose readers should not regard the message as addressed to them.

BCC

This field contains additional mailing addresses to send the message to, which should not appear in the header of the message actually sent. Copies sent this way are called blind carbon copies.

To send a blind carbon copy of every outgoing message to yourself, set the variable mail-self-blind to t.

FCC

This field contains the name of one file (in system mail file format) to which a copy of the message should be appended when the message is sent. Do not output directly into an Rmail file with FCC; instead, output to an inbox file and “get new mail” from that inbox file into the Rmail file. @xref{Rmail Inbox}.

From

Use the ‘From’ field to say who you are, when the account you are using to send the mail is not your own. The contents of the ‘From’ field should be a valid mailing address, since replies will normally go there.

Reply-to

Use this field to direct replies to a different address. Most mail-reading programs (including Rmail) automatically send replies to the ‘Reply-to’ address in preference to the ‘From’ address. By adding a ‘Reply-to’ field to your header, you can work around any problems your ‘From’ address may cause for replies.

If you want to put the same ‘Reply-to’ address into every outgoing message, set the variable mail-default-reply-to to that address (as a string).

In-reply-to

This field contains a piece of text describing a message you are replying to. Some mail systems can use this information to correlate related pieces of mail. Normally this field is filled in by Rmail when you are replying to a message in Rmail, and you never need to think about it (@pxref{Rmail}).

The ‘To’, ‘CC’, ‘BCC’ and ‘FCC’ fields can appear any number of times, to specify many places to send the message.

The ‘To’, ‘CC’, and ‘BCC’ fields can have continuation lines. All the lines starting with whitespace, following the line on which the field starts, are considered part of the field. For example,

To: foo@here.net, this@there.net,
  me@gnu.cambridge.mass.usa.earth.spiral3281

If the variable mail-archive-file-name is non-nil, it should be a string naming a file; every time you start to edit a message to send, the message starts out with an ‘FCC’ field specifying that file. Unless you remove the ‘FCC’ field before sending, the message will be written into that file when it is sent.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.3 Mail Aliases

You can define mail aliases in a file named ‘~/.mailrc’. These are short mnemonic names stand for mail addresses or groups of mail addresses. Like many other mail programs, Emacs expands aliases when they occur in the ‘To’, ‘CC’, and ‘BCC’ fields.

To define an alias in ‘~/.mailrc’, write a line in the following format:

alias shortaddress fulladdress

For instance, if you send want to use maingnu as a short form of the address gnu@prep.ai.mit.edu, put in the line:

alias maingnu gnu@prep.ai.mit.edu

The file ‘~/.mailrc’ is used primarily by other mail-reading programs; it can contain various other commands. Emacs ignores everything in it except for alias definitions.

Another way to define a mail alias, within Emacs alone, is with the define-mail-alias command. It prompts for the alias and then the full address. You can use it to define aliases in your ‘.emacs’ file, like this:

(define-mail-alias "maingnu" "gnu@prep.ai.mit.edu")

define-mail-alias records aliases by adding them to a variable named mail-aliases. If your are comfortable with manipulating Lisp lists, you can set mail-aliases directly. The initial value of mail-aliases is t, which means that Emacs should read ‘.mailrc’ to get the proper value.

Normally, Emacs expands aliases when you send the message. If you like, you can have mail aliases expand as abbrevs, as soon as you type them in. To enable this feature, execute the following:

(add-hook 'mail-setup-hook 'mail-abbrevs-setup)

This can go in your ‘.emacs’ file. @xref{Hooks}.

Note that abbrevs expand only if you insert a word-separator character afterward. However, any mail aliases that you didn’t expand in the mail buffer are expanded subsequently when you send the message. @xref{Abbrevs}.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.4 Mail Mode

The major mode used in the ‘*mail*’ buffer is Mail mode, which is much like Text mode except that various special commands are provided on the C-c prefix. These commands all have to do specifically with editing or sending the message.

C-c C-s

Send the message, and leave the ‘*mail*’ buffer selected (mail-send).

C-c C-c

Send the message, and select some other buffer (mail-send-and-exit).

C-c C-f C-t

Move to the ‘To’ header field, creating one if there is none (mail-to).

C-c C-f C-s

Move to the ‘Subject’ header field, creating one if there is none (mail-subject).

C-c C-f C-c

Move to the ‘CC’ header field, creating one if there is none (mail-cc).

C-c C-w

Insert the file ‘~/.signature’ at the end of the message text (mail-signature).

C-c C-y

Yank the selected message from Rmail (mail-yank-original). This command does nothing unless your command to start sending a message was issued with Rmail.

C-c C-q

Fill all paragraphs of yanked old messages, each individually (mail-fill-yanked-message).

There are two ways to send the message. C-c C-s (mail-send) sends the message and marks the ‘*mail*’ buffer unmodified, but leaves that buffer selected so that you can modify the message (perhaps with new recipients) and send it again. C-c C-c (mail-send-and-exit) sends and then deletes the window or switches to another buffer. It puts the ‘*mail*’ buffer at the lowest priority for reselection by default, since you are finished with using it. This is the usual way to send the message.

Mail mode provides some other special commands that are useful for editing the headers and text of the message before you send it. There are three commands defined to move point to particular header fields, all based on the prefix C-c C-f (‘C-f’ is for “field”). They are C-c C-f C-t (mail-to) to move to the ‘To’ field, C-c C-f C-s (mail-subject) for the ‘Subject’ field, and C-c C-f C-c (mail-cc) for the ‘CC’ field. These fields have special motion commands because they are the most common fields for the user to want to edit.

C-c C-w (mail-signature) adds a standard piece text at the end of the message to say more about who you are. The text comes from the file ‘.signature’ in your home directory.

To insert signatures automatically, set the variable mail-signature non-nil; then starting a mail message automatically inserts the contents of your ‘.signature’ file. If you want to omit your signature from a particular message, delete it from the buffer before you send the message.

When mail sending is invoked from the Rmail mail reader using an Rmail command, C-c C-y can be used inside the ‘*mail*’ buffer to insert the text of the message you are replying to. Normally it indents each line of that message four spaces and eliminates most header fields. A numeric argument specifies the number of spaces to indent. An argument of just C-u says not to indent at all and not to eliminate anything. C-c C-y always uses the current message from the ‘RMAIL’ buffer, so you can insert several old messages by selecting one in ‘RMAIL’, switching to ‘*mail*’ and yanking it, then switching back to ‘RMAIL’ to select another.

You can specify the text for C-c C-y to insert at the beginning of each line: set mail-yank-prefix to the desired string. (A value of nil means to use indentation; this is the default.) However, C-u C-c C-y never adds anything at the beginning of the inserted lines, regardless of the value of mail-yank-prefix.

After using C-c C-y, you can use the command C-c C-q (mail-fill-yanked-message) to fill the paragraphs of the yanked old message or messages. One use of C-c C-q fills all such paragraphs, each one individually.

Mail mode defines the character ‘%’ as part of a word; this is helpful for using the word commands to edit mail addresses.

Turning on Mail mode (which C-x m does automatically) runs the normal hooks text-mode-hook and mail-mode-hook. Initializing a new outgoing message runs the normal hook mail-setup-hook; if you want to add special fields to your mail header or make other changes to the appearance of the mail buffer, use that hook. @xref{Hooks}.

The main difference between these hooks is just when they are invoked. Whenever you type M-x mail, mail-mode-hook runs as soon as the ‘*mail*’ buffer is created. Then the mail-setup function puts in the default contents of the buffer. After these default contents are inserted, mail-setup-hook runs.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

1.5 Distracting the NSA

M-x spook adds a line of randomly chosen keywords to an outgoing mail message. The keywords are chosen from a list of words that suggest you are discussing something subversive.

The idea behind this feature is that the suspicion that the NSA snoops on all electronic mail messages that contain keywords suggesting they might be interested. (The NSA says they don’t, but there is no way to be certain.) The idea is that if lots of people add suspicious words to their messages, the NSA will get so busy with spurious input that they will have to give up reading it all.

Whether or not this confuses the NSA, it at least amuses people.


[Top] [Contents] [Index] [ ? ]

About This Document

This document was generated on March 29, 2022 using texi2html 5.0.

The buttons in the navigation panels have the following meaning:

Button Name Go to From 1.2.3 go to
[ << ] FastBack Beginning of this chapter or previous chapter 1
[ < ] Back Previous section in reading order 1.2.2
[ Up ] Up Up section 1.2
[ > ] Forward Next section in reading order 1.2.4
[ >> ] FastForward Next chapter 2
[Top] Top Cover (top) of document  
[Contents] Contents Table of contents  
[Index] Index Index  
[ ? ] About About (help)  

where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:


This document was generated on March 29, 2022 using texi2html 5.0.